<template>
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox :label="item.id" v-for="item in list" :key="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="assignRolesFn">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRolesAPI } from '@/api/setting.js'
import { getUserDetailAPI, assignRolesAPI } from '@/api/employees'
export default {
  props: {
    curEmployeId: {
      require: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  created() {
    this.getRoles()
    this.getUserDetail()
  },
  methods: {
    closeDialog() {
      this.$emit('closeFn')
    },
    async getRoles() {
      const res = await getRolesAPI()
      this.list = res.data.rows
    },
    async getUserDetail() {
      const res = await getUserDetailAPI(this.curEmployeId)
      this.roleIds = res.data.roleIds
    },
    async assignRolesFn() {
      const res = await assignRolesAPI({ id: this.curEmployeId, roleIds: this.roleIds })
      console.log(res)
      this.$emit('closeFn')
    }
  }
}
</script>
